package com.example.demo.utils;


import groovy.lang.Binding;
import groovy.lang.GroovyShell;

import java.util.Map;

public class GroovyUtils {

    public Map<String ,Object> groovyRun(String str , Map<String ,Object> map){
        Binding binding= new Binding();
        binding.setProperty("map",map);
//        Iterator<Map.Entry<String, Object>> itEntry = map.entrySet().iterator();
//        while (itEntry.hasNext()) {
//            Map.Entry<String, Object> next = itEntry.next();
//            binding.setVariable(next.getKey(),next.getValue());
//        }
        GroovyShell groovyShell =new GroovyShell(binding);
        groovyShell.evaluate(str);
        Map<String ,Object> result = binding.getVariables();
        result.get("result");
        return result;
    }
}
